package com.epam.web_project.bank.command.show_commands;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.epam.web_project.bank.command.Command;
import com.epam.web_project.bank.dao.customer_dao.CustomerDAO;
import com.epam.web_project.bank.dao.factory.MySQLDAOFactory;
import com.epam.web_project.bank.db.ConnectionPool;
import com.epam.web_project.bank.entity.Customer;
import com.epam.web_project.bank.util.AppPropertiesLoader;

public class ShowUserInfoCommand implements Command {

	// show admin the user info for the approval
	@Override
	public String execute(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		AppPropertiesLoader props = AppPropertiesLoader.getInstance();
		int userId = -1;
		if (request.getParameter("custId") != null) {
			userId = Integer.valueOf(request.getParameter("custId"));
		} else {
			return props.getProperty("show_main_command");
		}
		MySQLDAOFactory daoFactory = new MySQLDAOFactory();
		daoFactory.setConnectionPool(ConnectionPool.getInstance());
		CustomerDAO customerDAO = daoFactory.getCustomerDAO();
		Customer customer = customerDAO.findById(userId);
		request.setAttribute("customer", customer);
		return props.getProperty("uanpproved_user_info");
	}

}
